package com.wyy.mapper;

import com.wyy.pojo.Comments;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @program: gytcb
 * @author: 吴磊
 * @create: 2021-06-03 20:21
 */
@Repository
public interface CommentMapper {
    /**
     * 添加评论
     *
     * @param comments
     * @return
     */
    Integer insertComment(Comments comments);

    /**
     * 获取文章的评论数
     *
     * @param articleId
     * @return
     */
    @Select("select article_comment_count from articles where article_id = #{articleId}")
    Integer getArticleCommentCount(@Param("articleId") String articleId);

    /**
     * 通过评论Id删除评论
     *
     * @param commentId
     * @return
     */
    @Delete("delete from comments where comment_id  = #{commentId}")
    Integer deleteCommentById(@Param("commentId") String commentId);

    /**
     * 根据评论Id获取文章Id
     *
     * @param commentId
     * @return
     */
    @Select("select article_id from comments where comment_id  = #{commentId}")
    String getArticleIdByCommentId(@Param("commentId") String commentId);

    /**
     * 根据文章ID获取评论
     *
     * @param articleId
     * @param curPage
     * @return
     */
    List<Comments> getCommentByArticleId(@Param("articleId") String articleId, @Param("curPage") int curPage);

    /**
     * 根据用户ID获取评论总数
     *
     * @param userId
     * @return
     */
    @Select("select count(1) from comments where user_id = #{userId}")
    Integer getUserCommentCount(@Param("userId") String userId);

    /**
     * 根据用户ID获取没有匿名的评论总数
     *
     * @param userId
     * @return
     */
    @Select("select count(1) from comments where user_id = #{userId} and comments_status = 1 ")
    Integer getUserCommentCountNotNnonymous(@Param("userId") String userId);

    /**
     * 查询用户评论
     *
     * @param userId
     * @param curPage
     * @return
     */
    List<Comments> getUserComments(@Param("userId") String userId, @Param("curPage") int curPage);

    /**
     * 查询用户没有匿名的评论
     *
     * @param userId
     * @param curPage
     * @return
     */
    List<Comments> getUserCommentsNotNnonymous(@Param("userId") String userId, @Param("curPage") int curPage);
}
